var optionDatas = {
    "deaf.jsp": "耳聋基因检测",
//                "dipin.jsp": "地贫筛查",
//                "HPV.jsp": "HPV检测",
    "nifty.jsp": "NIPT检测",
               "akxChildGenTest.jsp": "新生儿疾病筛查",
//                "sample1.html": "产前血清学筛查",
//                "sample2.html": "乳腺癌筛查"
};
function getJsonFromUrl() {
    var query = location.search.substr(1);
    var result = {};
    query.split("&").forEach(function (part) {
        var item = part.split("=");
        result[item[0]] = decodeURIComponent(item[1]);
    });
    return result;
}
function changeSample(value) {

    document.querySelector("#my-iframe").src = value + (isEdit ? "?edit=true" : "");
}

var params = getJsonFromUrl();
var isEdit;
var file = params.file;
if (params.edit && file && optionDatas[file]) { 
    //编辑送检单
   isEdit = true;
    changeSample(file);
    $(".sample").html("<h2>编辑送检单：" + optionDatas[file] + "</h2>")
    setInterval(()=>{
        var isSampleEditSuccess = !! sessionStorage.getItem("sampleEditSuccess", false);
    if(isSampleEditSuccess) {
        sessionStorage.removeItem("sampleEditSuccess");
        //window.location.href = "sample-list.jsp";
        callParent('编辑送检单','/csfy/static/manage-sys/sample-list.html?operate=edit');
        //关闭当前tab
        closeCurrentTab("编辑送检单详情");
    }
},1000);
} else {
    var optionHtml = "";
    Object.keys(optionDatas).map(key => {
        optionHtml += "<option value='" + key + "'>" + optionDatas[key] + "</option>";
});
    $("#my-select").html(optionHtml);
}


//添加tab
function callParent(title,url) {
    // var menuName=parent.$('#tt').tabs('getSelected').panel('options').title;
    //如果存在，直接刷新页面
    if (parent.$('#tt').tabs('exists', title)) {
        parent.$('#tt').tabs('close', title);
        window.parent.addTab(title, url);
    } else {
        window.parent.addTab(title, url);
    }
}

//关闭当前tab
function closeCurrentTab(title) {
    parent.$("#tt").tabs('close',title);
}